<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>遥控器</title>
</head>

<body>
    <button id="btn">按我</button>
</body>
<script src="./macroCommand.js"></script>
<script>
    const openAcCommand = {
        execute() {
            console.log('打开冰箱');
        }
    }

    const openTvCommand = {
        execute() {
            console.log('打开电视');
        }
    }
    const openSoundCommand = {
        execute() {
            console.log('打开音响');
        }
    }
    let macroCommand1 = new MacroCommand();
    macroCommand1.add(openTvCommand);
    macroCommand1.add(openSoundCommand);

    const closeDoorCommand = {
        execute() {
            console.log('关门');
        }
    }
    const openPCCommand = {
        execute() {
            console.log('开电脑');
        }
    }
    const openWechatCommand = {
        execute() {
            console.log('登录微信');
        }
    }
    let macroCommand2 = new MacroCommand();
    macroCommand2.add(closeDoorCommand);
    macroCommand2.add(openPCCommand);
    macroCommand2.add(openWechatCommand);

    // 组合成一个超级命令
    let macroCommand = new MacroCommand();
    macroCommand.add(openAcCommand);
    macroCommand.add(macroCommand1);
    macroCommand.add(macroCommand2);

    let setCommand = ((command) => {
        document.getElementById('btn').onclick = () => {
            command.execute();
        }
    })(macroCommand);
</script>

</html>